#!/bin/sh

if [ "$UID" -ne "0" ]; then
        echo "You need to run $@ as root."
        exit 1
fi

echo 2000 > /proc/sys/vm/min_free_kbytes

export TMPDIR=/var
export LD_LIBRARY_PATH="/lib:/usr/lib:/home/yx5532/lib"

telnetd 2>/dev/null &

echo 2000 > /proc/sys/vm/min_free_kbytes
echo 3000000 > /proc/sys/net/core/rmem_default
echo 3000000 > /proc/sys/net/core/rmem_max

cd /home/yx5532/lib
insmod hiether.ko
ifconfig eth0 10.0.0.248 netmask 255.0.0.0 hw ether $mac
route add default gw 10.0.0.6


insmod ./mmz.ko mmz=others,0,0xc5000000,48M
insmod ./hidmac.ko
insmod ./tde.ko
insmod ./hi3560E.ko MsgBufSize=524288 g_VdecTypeString="H264" g_VdecFrameNum=1
insmod ./epl.ko
insmod ./fb.ko
insmod ./hifb.ko video="hifb:vram0_size:8294400,vram1_size:8000000"
insmod ./jpeg.ko


insmod ehci-hcd.ko
insmod usbserial.ko
insmod pl2303.ko
if [ -f /home/yx5532/lib/rt73.ko ];then
insmod rt73.ko
fi
if [ -f /home/yx5532/lib/rt3070sta.ko ];then
insmod rt3070sta.ko
fi
if [ -f /home/yx5532/lib/rt3572sta.ko ];then
insmod rt3572sta.ko
fi
insmod hi_ir.ko

/home/yx5532/bin/fix_roothome.elf

# Do upgrade phase 2
/home/yx5532/bin/ysupgrade.elf 1

#support igmp version 2
echo 2 > /proc/sys/net/ipv4/conf/all/force_igmp_version

#optimize the tcp/ip stack
echo 2000000 > /proc/sys/net/core/rmem_default
echo 3000000 > /proc/sys/net/core/rmem_max
echo 2000 > /proc/sys/vm/min_free_kbytes
echo 2000000 > /proc/sys/net/core/wmem_default
echo 3000000 > /proc/sys/net/core/wmem_max
#echo 0 > /proc/sys/net/ipv4/tcp_timestamps
echo 1 > /proc/sys/net/ipv4/tcp_timestamps
echo 1 > /proc/sys/net/ipv4/tcp_sack
echo 1 > /proc/sys/net/ipv4/tcp_window_scaling

if [ -x /home/yx5532/bin/certus_main ]; then
          cd /home/yx5532/bin/
          ./certus_main &
fi

case "$runlevel" in
        "1"*)
                if [ -x /home/yx5532/telecom/telecom.elf ]; then
                        cd /home/yx5532/telecom/
                        #../bin/gdb telecom.elf -ex=run
                        ./telecom.elf
                fi
                ;;
        "4"*)
                if [ -x /home/yx5532/bin/factorytest.elf ]; then
                	insmod /home/yx5532/lib/hibios.ko
                	insmod /home/yx5532/lib/poweroff_drv.ko
                        cd /home/yx5532/bin/
                        ./factorytest.elf $runlevel
                fi
                ;;
        *)
                echo "runlevel wrong! do nothing..."
				/sbin/getty -L ttyS000 115200 vt100 -n root -I "Auto login as root ..." &
                break
                ;;
esac

exit 0
